package array.leetcode.medium;

/**
 * @author bruin_du
 * @description 二维数组中的查找
 * @date 2022/5/10 18:09
 **/
public class offer04_FindNumberIn2DArray {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0)
            return false;
        int row = matrix.length;
        int col = matrix[0].length;
        int xRow = row - 1,xCol = 0;
        while(xRow >= 0 && xCol < col){
            if(target > matrix[xRow][xCol])
                xCol++;
            else if(target == matrix[xRow][xCol])
                return true;
            else
                xRow--;
        }
        return false;
    }
}
